//定义懒加载插件
import {useIntersectionObserver} from '@vueuse/core'

export const lazyPlugin = {
    //固定install
    install(app) {
        //懒加载逻辑
        app.directive('img-lazy', {
            mounted(el, binding) {
                //el 是绑定的元素
                //binding binding.value是指令等于号后面绑定的表达式的值 即img的url
                console.log(el, binding.value);
                useIntersectionObserver
                (
                    el,
                    ([{isIntersecting}]) => {
                        console.log(isIntersecting);
                        if (isIntersecting) {
                            el.src = binding.value
                        }
                    }
                )
            }
        })
    }


}